package top.huhuiyu.spirngboot2.total.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.huhuiyu.spirngboot2.total.anno.Limit;
import top.huhuiyu.spirngboot2.total.aop.LimitMode;
import top.huhuiyu.spirngboot2.total.base.BaseResult;

@RestController
@RequestMapping("/test")
public class TestController {

    @Limit(key = "bucketLimit", mode = LimitMode.BUCKET_LIMIT, time = 5 * 60 * 1000, limit = 10)
    @GetMapping("/bucketLimit")
    public BaseResult bucketLimit() {
        return BaseResult.ok("通过桶限流");
    }

    @Limit(key = "ipBucketLimit", mode = LimitMode.IP_BUCKET_LIMIT, time = 5 * 60 * 1000, limit = 10)
    @GetMapping("/ipBucketLimit")
    public BaseResult ipBucketLimit() {
        return BaseResult.ok("通过ip桶限流");
    }

    @Limit(key = "limit", mode = LimitMode.IP_LiMIT, time = 20 * 1000, sleep = 10 * 1000)
    @GetMapping("/limit")
    public BaseResult limit() {
        return BaseResult.ok("通过ip限流");
    }
}
